<template>
  <div id="AlbumUpload">
    <el-form :model="albumData" :rules="fromRules" ref="form">
      <el-form-item prop="name">
        <div>
          相册名称
          <el-input type="input" v-model="albumData.name" clearable placeholder="请输入相册名称"></el-input>
        </div>
      </el-form-item>
    </el-form>
    <el-button @click="submit" type="success">提交</el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      albumData: {
        name: '', // 上传相册名称
      }, // 相册数据
      fromRules: {
        name: [
          { required: true, message: '请输入相册名称', trigger: 'blur' },
        ],
      }, // 表单规则
    }
  },
  methods: {
    // 上传相册事件
    submit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.$axios({
            method: 'post',
            url: '/album/login/addAlbum/' + this.albumData.name
          }).then(res => {
            if (res.data) {
              this.$message({
                showClose: true,
                message: '创建成功',
                type: 'success',
              })
            } else {
              this.$message({
                showClose: true,
                message: '创建失败，出现错误了X.X',
                type: 'error',
              })
            }
          })
        } else {
          this.$message({
            message: '请完善信息再提交哦~',
            type: 'error',
            showClose: true
          })
        }
      })
    },
  }
}
</script>

<style lang="scss" scoped>
#AlbumUpload {
  display: flex;
  flex-direction: column;
  padding: 20px;
}
</style>
<style scoped="scoped" scope>
/deep/.el-input__inner {
  background-color: #202020;
  text-align: center;
  color: #fff;
  width: 300px;
}
</style>